package com.example.pwj.ffstudy.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.blankj.utilcode.util.FragmentUtils;
import com.example.pwj.ffstudy.R;
import com.example.pwj.ffstudy.ui.activity.ContainerActivity;

/**
 * Created by pwj on 2017/8/24.
 */

public class FmManager {
    public static final String FRAGMENT_NAME = "fragment_name";
    public static final String BUNDLE_DATA = "bundle_data";


    public static void startAct(Fragment arcfragment, String destName) {
        startAct(arcfragment,destName,null);
    }

    /**
     *
     * 跳转到ContainerActivity
     * @param arcFragment 源fragment
     * @param destName    目的fragment的类名
     * @param bundle      携带的其他数据
     */
    public static void startAct(Fragment arcFragment, String destName,Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(arcFragment.getContext(), ContainerActivity.class);
        if (bundle == null) {
            bundle = new Bundle();
        }
        bundle.putString(FRAGMENT_NAME, destName);
        intent.putExtra(BUNDLE_DATA, bundle);
        arcFragment.startActivity(intent);
        arcFragment.getActivity().overridePendingTransition(R.anim.activity_right_in, R.anim.activity_left_out);
    }

    /**
     * 根据类名取fragment
     * @param fragmentName
     * @return
     */
    public static Fragment getFragmentByName(String fragmentName) {
        Fragment fragment = null;
        try {
            fragment = (Fragment) Class.forName(fragmentName).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return fragment;
    }

}
